package com.study.concurrent.B_ThreadSynchronizedBasic.f_UseReadWriteLock;

/**
 * Created by 赵超 on 2017/3/23.
 */
public class Writer implements Runnable {
    private PricesInfo pricesInfo;

    public Writer(PricesInfo pricesInfo) {
        this.pricesInfo = pricesInfo;
    }

    /**
     * 循环修改两个价格 3 次，每次修改之后线程休眠 2 秒
     */
    @Override
    public void run() {
        for (int i = 0; i < 3; i++) {
            System.out.printf("Writer : 准备修改价格\n");
            double price1 = Math.random() * 10;
            double price2 = Math.random() * 8;
            pricesInfo.setPrices(price1, price2);
            System.out.printf("Writer : 价格修改完毕 Price1:%f Price2:%f\n",
                    price1, price2);
            try {
                Thread.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
